/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[InitServlet.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package mvc.controller;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import mvc.dao.factory.StudentDaoFactory;

/**
 * 一个负责初始化StudentDaoFactory的Servlet
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
@WebServlet(name = "InitServlet", urlPatterns = "/initServlet", loadOnStartup = 1)
public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = 3393145229254360784L;

	@Override
	public void init() throws ServletException {
		System.out.println("==============init==============");
		Properties properties = new Properties();
		try {
			properties.load(this.getServletContext().getResourceAsStream("/WEB-INF/classes/daoconfig.properties"));
			String type = properties.getProperty("type");

			if (type == null) {
				StudentDaoFactory.getInstance().setType("JDBC");
			} else {
				StudentDaoFactory.getInstance().setType(type);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
